//
//  CMDBRegisterTF.swift
//  CMDB
//
//  Created by 王磊 on 05/05/2017.
//  Copyright © 2017 CMDB. All rights reserved.
//

import UIKit



class CMDBRegisterTF: TSBaseView {
    
    private var textLabel: UILabel = UILabel()
    
    internal var textWidth: CGFloat {
        
        if let attrText = attrText {
            
            return (attrText.mutableString as String).suitToSize(CGSizeMake(99, 99), fontSize: CMDB_Register_TF_FONT_Size, lineSpacing: 2).width + 5
        }
        return 0
    }
    
    private var singleLine: UIView = UIView()
    
    internal var attrText: NSMutableAttributedString? {
        willSet {
            
            if let newValue = newValue {
                
                textLabel.setAttr(newValue)
                
                setNeedsDisplay()
            }
   
        }
    }
}
extension CMDBRegisterTF {
    
    override func addOwnSubviews() {
        super.addOwnSubviews()
        
        addSubview(textLabel)
        
        addSubview(singleLine)
    }
    override func configOwnSubviews() {
        super.configOwnSubviews()
        
        textLabel.textColor = UIColor.lightGrayColor()
        
        textLabel.textAlignment = .Left
        
        singleLine.backgroundColor = word12Color
        
    }
}

extension CMDBRegisterTF {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        textLabel.snp_makeConstraints { [weak self](make) in
            
            make.left.equalTo(0)
            
            make.width.equalTo(self!.textWidth)
            
            make.centerY.equalTo(5)
            
        }
        singleLine.snp_makeConstraints { (make) in
            
            make.left.equalTo(0)
            
            make.right.equalTo(0)
            
            make.bottom.equalTo(0)
            
            make.height.equalTo(1 * CMDB_Rate)
        }
    }
}